package com.tsu.mall.admin.controller;

import com.tsu.mall.common.entity.Wares;
import com.tsu.mall.common.service.IWaresService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/")
public class IndexController {
    @Autowired
    private IWaresService iWaresService;
    @GetMapping("/index")
    public String indexPage(){
        return "index";
    }
    @GetMapping("/HomePage")
    public String HomePage(Model model) {
        //查询商品销量前五的商品的信息
        List<Wares> Top5WaresInfo=iWaresService.selectSellTop5Wares();
        for(int i=0;i<Top5WaresInfo.size(); i++){
            Top5WaresInfo.get(i).setTopWaresNum(i+1);
        }
        model.addAttribute("Top5WaresInfo",Top5WaresInfo);
        //查询销量6-10的商品的信息
        List<Wares> Top6to10WaresInfo=iWaresService.selectSellTop6to10WaresInfo();
        for(int i=0;i<Top6to10WaresInfo.size(); i++){
            Top6to10WaresInfo.get(i).setTopWaresNum(i+6);
        }
        model.addAttribute("Top6to10WaresInfo",Top6to10WaresInfo);
        return "home";
    }
}
